from django.db import models
from django.contrib.auth import get_user_model

from movies.models import MovieDetail

User = get_user_model()


# Create your models here.

class UserWantMovie(models.Model):
    user = models.ForeignKey(User, verbose_name='点击想看电影的用户', help_text='点击想看电影的用户')
    movie = models.ForeignKey(MovieDetail, verbose_name='想看的电影', help_text='想看得电影')
    add_time = models.DateTimeField(auto_now=True, verbose_name='操作的时间', help_text='操作的时间')

    class Meta:
        verbose_name = '用户点击想看电影'
        verbose_name_plural = verbose_name
        unique_together = ("user", "movie")

    def __str__(self):
        return "用户:{},电影:{}".format(self.user.username, self.movie.name)


class UserStarMovie(models.Model):
    STAR = (
        ('1', '1'),
        ('2', '2'),
        ('3', '3'),
        ('4', '4'),
        ('5', '5'),
        ('6', '6'),
        ('7', '7'),
        ('8', '8'),
        ('9', '9'),
        ('10', '10'),
    )

    user = models.ForeignKey(User, verbose_name='评价用户', help_text='评价用户')
    movie = models.ForeignKey(MovieDetail, verbose_name='想看的电影', help_text='想看得电影')
    add_time = models.DateTimeField(auto_now=True, verbose_name='操作的时间', help_text='操作的时间')
    star = models.CharField(max_length=2, choices=STAR, verbose_name='用户评分', help_text='用户评分')

    class Meta:
        verbose_name = '用户评分电影'
        verbose_name_plural = verbose_name
        unique_together = ("user", "movie")

    def __str__(self):
        return "用户:{},电影:{},分数:{}".format(self.user.username, self.movie.name, self.star)


class UserMovieShortComments(models.Model):
    # 同时使用了两个或以上相同的外键你就需要给定其他外键related_name
    user = models.ForeignKey(User, verbose_name='短评的用户', help_text='短评的用户', related_name='short_comment_user')
    movie = models.ForeignKey(MovieDetail, verbose_name='短评的电影', help_text='短评的电影', null=True, default=None)
    add_time = models.DateTimeField(auto_now=True, verbose_name='操作的时间', help_text='操作的时间')
    comments = models.TextField(max_length=200, blank=False, verbose_name='用户评论', help_text='用户评论')
    fav_user = models.ManyToManyField(User, verbose_name='点赞的用户(短评)', help_text='点赞的用户')
    relay_to = models.ForeignKey('self', blank=True, null=True, default=None, verbose_name='回复短评', help_text='回复短评')

    class Meta:
        verbose_name = '用户对一个电影进行短评论'
        verbose_name_plural = verbose_name

        permissions = (
            ('can_not_add_shortcomments','用户不能去发帖'),
            ('can_delete_shortcomments','可以删帖'),
            ('can_update_shortcomments', '可以修改帖子'),
            ('can_read_shortcomments','可以查看帖子(个人中心)')

        )

    def __str__(self):
        return "用户:{},短评电影:{}".format(self.user.username, self.movie.name)

